<template>
  <div v-loading="loading" style="margin-top: 70px">
    <div class="paixi">
      <el-table
        :data="state.tableData"
        style="width: 100%; padding: 15px; padding-top: 0px"
        :header-cell-style="{
          backgroundColor: 'var(--tableheaderback)',
          color: 'var(--tableheadercolor)',
          border: '2px solid var(--tableborder)',
        }"
        :cell-style="{ border: '2px solid var(--tableborder)' }"
        stripe
        border
      >
        <!-- <el-table-column
          v-for="(item, index) in state.oldList"
          :key="`col_${index}`"
          :prop="state.columns[index].prop"
          align="center"
          :label="item.label"
          width="150px"
        >
        </el-table-column> -->
        <el-table-column
          prop="AnnounceDate"
          align="center"
          :label="state.oldList[0].label"
          min-width="150px"
        />
        <el-table-column
          prop="YearEnd"
          align="center"
          :label="state.oldList[1].label"
          min-width="150px"
        />
        <el-table-column
          prop="Period"
          align="center"
          :label="state.oldList[2].label"
          min-width="150px"
        />
        <el-table-column
          prop="Particular"
          align="center"
          :label="state.oldList[3].label"
          min-width="150px"
        >
          <template v-slot="{ row }">
            <div class="particular" v-if="lang=='en'">
              <div class="item" v-for="(item,index) in row.Particular.split(' ')" :key="index">
                  {{item}}
              </div>
            </div>
             <div class="particular" v-else>
              {{row.Particular}}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="BookCloseTo"
          align="center"
          :label="state.oldList[4].label"
          min-width="150px"
        />
        <el-table-column
          prop="PayDate"
          align="center"
          :label="state.oldList[5].label"
          min-width="150px"
        />
        <el-table-column
          prop="ExDate"
          align="center"
          :label="state.oldList[6].label"
          min-width="150px"
        />
      </el-table>
    </div>
    <div class="footer" v-if="footer">
      D:Dividend SD:Special Cash Dividend B:Bonus Share BW:Bonus Warrant
      R:Rights Issue S:Share Subdivision C:Share Consolidation O:Open Offer
    </div>
    <div class="zhanwei" style="height: 50px; width: 100vw"></div>
  </div>
</template>

<script lang="ts">
export default {
  name: "Financial",
};
</script>

<script lang="ts" setup>
import {
  ref,
  onMounted,
  reactive,
  computed,
  watch,
  getCurrentInstance,
} from "vue";
import X2js from "x2js";
import { getEntitlementHistory } from "@/api/axios/reqTest";
import Sortable from "sortablejs";
const { proxy } = getCurrentInstance() as any;
const arr: any = [];
const loading = ref(false);
const state = reactive({
  oldList: [
    {
      label: proxy.$t("home.AnnounceDate"),
      prop: "AnnounceDate",
    },
    {
      label: proxy.$t("home.YearEnd"),
      prop: "YearEnd",
    },
    {
      label: proxy.$t("home.Period"),
      prop: "Period",
    },
    {
      label: proxy.$t("home.Particular"),
      prop: "Particular",
    },
    {
      label: proxy.$t("home.BookCloseTo"),
      prop: "BookCloseTo",
    },
    {
      label: proxy.$t("home.PayDate"),
      prop: "PayDate",
    },
    {
      label: proxy.$t("home.ExDate"),
      prop: "ExDate",
    },
  ],
  columns: [
    {
      label: proxy.$t("home.AnnounceDate"),
      prop: "AnnounceDate",
    },
    {
      label: proxy.$t("home.YearEnd"),
      prop: "YearEnd",
    },
    {
      label: proxy.$t("home.Period"),
      prop: "Period",
    },
    {
      label: proxy.$t("home.Particular"),
      prop: "Particular",
    },
    {
      label: proxy.$t("home.BookCloseTo"),
      prop: "BookCloseTo",
    },
    {
      label: proxy.$t("home.PayDate"),
      prop: "PayDate",
    },
    {
      label: proxy.$t("home.ExDate"),
      prop: "ExDate",
    },
  ],
  tableData: [
    {
      AnnounceDate: "",
      YearEnd: "",
      Period: null,
      Particular: "",
      BookCloseTo: "",
      PayDate: "",
      ExDate: "",
    },
  ],
  tableConfig: {
    tableItems: [
      {
        label: proxy.$t("home.AnnounceDate"),
        prop: "AnnounceDate",
      },
      {
        label: proxy.$t("home.YearEnd"),
        prop: "YearEnd",
      },
      {
        label: proxy.$t("home.Period"),
        prop: "Period",
      },
      {
        label: proxy.$t("home.Particular"),
        prop: "Particular",
      },
      {
        label: proxy.$t("home.BookCloseTo"),
        prop: "BookCloseTo",
      },
      {
        label: proxy.$t("home.PayDate"),
        prop: "PayDate",
      },
      {
        label: proxy.$t("home.ExDate"),
        prop: "ExDate",
      },
    ],
  },
});
const footer = ref();
const lang = ref("");
onMounted(() => {
  test();
  // columnDrop1()
});

const test = async () => {
  const x2js = new X2js();
  loading.value = true;
  const xml = await getEntitlementHistory();
  const json:any = x2js.xml2js(xml as any);
  lang.value = json.EntilementHistory._Lang;

  const result: any = json;
  const data = result.EntilementHistory.GrpEntilementHistory.CopAct;
  footer.value = result.EntilementHistory.GrpRemarks.Remarks.Remark;
  console.log(data);
  state.tableData = data.slice(1).map((item: any) => {
    const {
      AnnounceDate,
      YearEnd,
      Period,
      Particular,
      BookCloseTo,
      PayDate,
      ExDate,
    } = item;
    return {
      AnnounceDate: AnnounceDate,
      YearEnd: YearEnd,
      Period: Period,
      Particular: Particular,
      BookCloseTo: BookCloseTo,
      PayDate: PayDate,
      ExDate: ExDate,
    };
  });
  loading.value = false;
};
const columnDrop1 = () => {
  //console.log(111)

  const tHeader = document.querySelector(
    `.paixi .el-table__header-wrapper tr`
  ) as HTMLElement;

  Sortable.create(tHeader, {
    animation: 180,
    /** 延迟 */
    // delay: 1,
    filter: ".disabled",
    onEnd: (evt: any) => {
      const oldItem = state.columns[evt.oldIndex];
      state.columns.splice(evt.oldIndex, 1);
      state.columns.splice(evt.newIndex, 0, oldItem);
    },
  });
};
</script>

<style lang="less" scoped>
.footer {
  background-color: var(--tableheaderback);
  width: 100vw;
  font-size: 0.6rem;
  color: var(--tableheadercolor);
  display: flex;
  justify-content: space-between;
}
.particular {
  display: flex;
  flex-wrap: wrap;
  .item {
    width: fit-content;
    margin-right: 5px;
  }
}
</style>
